﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.HVAC.Properties;
using YArchitech.LIB;

namespace YArchitech.HVAC
{
	public partial class LayAirTerminalMidForm : System.Windows.Forms.Form
	{
		public LayAirTerminalMidForm(HVACUserSetting userSetting, string name)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.initlbText(name);
			this.initXmlboot(name);
		}

		public LayAirTerminalMidForm(UserSetting userSetting, string name)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.initlbText(name);
			this.initXmlboot(name);
		}

		private void initlbText(string name)
		{
			this.Text = name + "居中布置";
		}

		private void initXmlboot(string name)
		{
			if (name == "风口")
			{
				this.xmlbootname = "ductlaymid";
				return;
			}
			if (name == "风盘")
			{
				this.xmlbootname = "coillaymid";
				return;
			}
			if (name == "喷头")
			{
				this.xmlbootname = "pipelaymid";
				return;
			}
			if (name == "器具")
			{
				this.xmlbootname = "PlumbingFixturelaymid";
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.hytbRowCount.Text.Trim() == "" || this.hytbColCount.Text.Trim() == "" || this.hytbTopDistance.Text.Trim() == "" || this.hytbBottomDistance.Text.Trim() == "" || this.hytbLeftDistance.Text.Trim() == "" || this.hytbRightDistance.Text.Trim() == "")
			{
				MessageBox.Show("所有参数均不能为空", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				return;
			}
			if (this.tabControl1.SelectedTab.Name == "tpGrid")
			{
				this.layMidParameter.Type = 0;
			}
			else if (this.tabControl1.SelectedTab.Name == "tpDistance")
			{
				this.layMidParameter.Type = 1;
			}
			this.layMidParameter.RowCount = Convert.ToInt32(this.hytbRowCount.Text.Trim());
			this.layMidParameter.ColCount = Convert.ToInt32(this.hytbColCount.Text.Trim());
			this.layMidParameter.TopDistance = Convert.ToDouble(this.hytbTopDistance.Text.Trim());
			this.layMidParameter.BottomDistance = Convert.ToDouble(this.hytbBottomDistance.Text.Trim());
			this.layMidParameter.LeftDistance = Convert.ToDouble(this.hytbLeftDistance.Text.Trim());
			this.layMidParameter.RightDistance = Convert.ToDouble(this.hytbRightDistance.Text.Trim());
			this.layMidParameter.RowDistance = double.Parse(this.hytbRow.Text.Trim());
			this.layMidParameter.ColDistance = double.Parse(this.hytbCol.Text.Trim());
			this.LaySettingWrite();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void LayAirTerminalAreaForm_Load(object sender, EventArgs e)
		{
			this.LaySettingInit();
		}

		private void LaySettingInit()
		{
			this.hytbRowCount.Text = this.userSettingS.GetValue(this.xmlbootname, "rowcount");
			this.hytbColCount.Text = this.userSettingS.GetValue(this.xmlbootname, "colcount");
			this.hytbTopDistance.Text = this.userSettingS.GetValue(this.xmlbootname, "topdistance");
			this.hytbBottomDistance.Text = this.userSettingS.GetValue(this.xmlbootname, "bottomdistance");
			this.hytbLeftDistance.Text = this.userSettingS.GetValue(this.xmlbootname, "leftdistance");
			this.hytbRightDistance.Text = this.userSettingS.GetValue(this.xmlbootname, "rightdistance");
			this.hytbRow.Text = this.userSettingS.GetValue(this.xmlbootname, "rowdistance");
			this.hytbCol.Text = this.userSettingS.GetValue(this.xmlbootname, "coldistance");
			this.layMidParameter.TopDistance = Convert.ToDouble(this.hytbTopDistance.Text.Trim());
			this.layMidParameter.BottomDistance = Convert.ToDouble(this.hytbBottomDistance.Text.Trim());
			this.layMidParameter.LeftDistance = Convert.ToDouble(this.hytbLeftDistance.Text.Trim());
			this.layMidParameter.RightDistance = Convert.ToDouble(this.hytbRightDistance.Text.Trim());
			this.layMidParameter.RowCount = Convert.ToInt32(this.hytbRowCount.Text.Trim());
			this.layMidParameter.ColCount = Convert.ToInt32(this.hytbColCount.Text.Trim());
			this.layMidParameter.RowDistance = double.Parse(this.hytbRow.Text.Trim());
			this.layMidParameter.ColDistance = double.Parse(this.hytbCol.Text.Trim());
		}

		private void LaySettingWrite()
		{
			this.userSettingS.WriteValue(this.xmlbootname, "rowcount", this.hytbRowCount.Text.Trim());
			this.userSettingS.WriteValue(this.xmlbootname, "colcount", this.hytbColCount.Text.Trim());
			this.userSettingS.WriteValue(this.xmlbootname, "topdistance", this.hytbTopDistance.Text.Trim());
			this.userSettingS.WriteValue(this.xmlbootname, "bottomdistance", this.hytbBottomDistance.Text.Trim());
			this.userSettingS.WriteValue(this.xmlbootname, "leftdistance", this.hytbLeftDistance.Text.Trim());
			this.userSettingS.WriteValue(this.xmlbootname, "rightdistance", this.hytbRightDistance.Text.Trim());
			this.userSettingS.WriteValue(this.xmlbootname, "rowdistance", this.hytbRow.Text.Trim());
			this.userSettingS.WriteValue(this.xmlbootname, "coldistance", this.hytbCol.Text.Trim());
		}

		private UserSetting userSettingS = new UserSetting();

		public LayMidParameter layMidParameter = new LayMidParameter();

		private string xmlbootname = "ductlaymid";
	}
}
